package com.woniuxy.mesboot.controller;

import com.woniuxy.mesboot.entity.MesInList;
import com.woniuxy.mesboot.service.MesInListService;
import com.woniuxy.mesboot.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("mesinlist")
@RestController
public class MesInListController {
    @Resource
    private MesInListService mesInListService;
    @GetMapping
    public Result queryAll(){
        List<MesInList> mesInLists = mesInListService.selectAll();
        return Result.ok().data("list",mesInLists);
    }

    @PostMapping()
    public Result insert(@RequestBody MesInList mesInList) {
        int i = mesInListService.insertSelective(mesInList);
        if (i > 0) {
            return Result.ok("添加成功");
        } else {
            return Result.error("添加失败");
        }
    }

    @GetMapping("{id}")
    public Result queryById(@PathVariable Long id) {
        MesInList mesInList = mesInListService.selectByPrimaryKey(id);
        return Result.ok().data("item",mesInList);

    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable Long id) {
        int i = mesInListService.deleteByPrimaryKey(id);
        if (i > 0) {
            return Result.ok("删除成功");

        } else {
            return Result.error("删除失败");
        }


    }

    @PutMapping
    public Result update(@RequestBody MesInList orders) {
        int i = mesInListService.updateByPrimaryKeySelective(orders);
        if (i > 0) {
            return Result.ok("修改成功");

        } else {
            return Result.error("修改失败");
        }
    }
}
